package com.qingcheng.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.Page;
import com.qingcheng.dao.TbAlbumMapper;
import com.qingcheng.pojo.goods.TbAlbum;
import com.qingcheng.service.TbAlbumService;
import com.qingcheng.util.PageUtil;
import tk.mybatis.mapper.entity.Example;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
*
* @author Simon
* @date 2020/07/27
*/
@Service
public class TbAlbumServiceImpl implements TbAlbumService {

    @Resource
    private TbAlbumMapper tbAlbumMapper;

    @Override
    public List<TbAlbum> queryAll() {
        List<TbAlbum> tbAlbum = tbAlbumMapper.selectAll();
            return tbAlbum;
    }

    @Override
    public PageUtil<TbAlbum> findListAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<TbAlbum> pages = (Page<TbAlbum>) tbAlbumMapper.selectAll();
        PageUtil<TbAlbum> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
    }


    @Override
    public PageUtil<TbAlbum> pageQueryByAll(Integer pageNum, Integer pageSize, TbAlbum tbAlbum) {

        Example example=new Example(TbAlbum.class);
        Example.Criteria criteria = example.createCriteria();
        // TODO 待实现 重新实现判断参数

        //if(!StringUtils.isEmpty(brand.getId())){
        //    criteria.andEqualTo("id",brand.getId());
        //}
        //if(!StringUtils.isEmpty(brand.getName())){
        //   criteria.andLike("name",brand.getName());
        //}
        PageHelper.startPage(pageNum,pageSize);
        Page<TbAlbum> pages = (Page<TbAlbum>) tbAlbumMapper.selectByExample(example);
        PageUtil<TbAlbum> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
     }


    @Override
    public boolean saveTbAlbum(TbAlbum tbAlbum) {
        int insert = tbAlbumMapper.insert(tbAlbum);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateTbAlbum(TbAlbum tbAlbum) {
        int i = tbAlbumMapper.updateByPrimaryKeySelective(tbAlbum);
        if(i>0){
            return true;
        }
        return false;
    }


    @Override
    public boolean deleteById(Integer id) {
        int i = tbAlbumMapper.deleteByPrimaryKey(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public TbAlbum findById(Integer id) {
        TbAlbum tbAlbum = tbAlbumMapper.selectByPrimaryKey(id);
        return tbAlbum;
    }
}
